package com.bird.business.utils;

import java.util.*;

public class FormatMapKey {
    //格式化map的key
    public static List<Map> format(List<Map> list){
        List<Map> temp = new ArrayList<>();
        if(list!=null&&list.size()!=0){
            for(int i=0;i<list.size();i++){
                Map res = list.get(i);
                Map tempMap = new HashMap();
                Set<Object> set= res.keySet();
                if(set!=null&&set.size()!=0) {
                    Iterator setKey = set.iterator();
                    while(setKey.hasNext()){
                        String key = setKey.next().toString();
                        String tempKey = changeWord(key);
                        tempMap.put(tempKey,res.get(key));
                    }
                }
                temp.add(tempMap);
            }
        }
        return temp;
    }
    //去横杠 横杠后面的字母大写
    public static String changeWord(String res){
        String[] words =  res.split("_");
        StringBuffer buf = new StringBuffer("");
        if(words!=null&words.length!=0){
            for(int i=0;i<words.length;i++){
                String tempWord = words[i];
                if(tempWord!=null&&tempWord.length()>1){
                    if(i==0){
                        buf.append(tempWord.toLowerCase());
                    }else{
                        buf.append(tempWord.substring(0,1).toUpperCase()+tempWord.substring(1).toLowerCase());
                    }
                }else{
                    buf.append("");
                }
            }
            return buf.toString();
        }else{
            return res;
        }
    }
}
